package com.purple;

import com.pink.RobotEx;
import com.purple.tasks.RightNowTask;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.SynchronousQueue;

public class Blind {
    private RobotEx robot;
    private LogAppender appender;
    private ExecutorService armLost;
    private SynchronousQueue<CPSignal> feedbackQueue;

    public Blind(RobotEx robot, LogAppender appender,
                 ExecutorService armLost,
                 SynchronousQueue<CPSignal> feedbackQueue) {

        this.robot = robot;
        this.appender = appender;
        this.armLost = armLost;
        this.feedbackQueue = feedbackQueue;
    }

    public void testmethod() {
        ColorPoint colorPoint = new ColorPoint(100, 200, 23, 33, 43);
        Runnable task = new RightNowTask(colorPoint,robot,appender,feedbackQueue);
        armLost.submit(task);
//        提交就阻塞等待结果
        CPSignal signal = null;
        try {
            signal = feedbackQueue.take();
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        if (signal.getSignal()){
            robot.moveAndClick(colorPoint.getX(),colorPoint.getY());
            appender.append("ggg");
        }


    }
}
